<?php
require 'db_conn.php';
$db->query('set names utf8');
$jg=$db->query('select * from t_message order by id desc');
$lynum=$jg->num_rows;  //留言总数
$page_size=5;//设置每页显示5条留言
$max_page= ceil($lynum/$page_size);  //19/5 =4
$page= isset($_GET['page'])?$_GET['page']:1;
$pre_page=$page-1;
if($pre_page<1) $pre_page=1;
$next_page=$page+1;
if($next_page>$max_page) $next_page=$max_page;
$begin=($page-1)*$page_size;  //每一页的起始记录数

$page_html="<a href='index.php?page=1'>首页</a>&nbsp;";
$page_html.="<a href='index.php?page=".$pre_page."'>上一页</a>&nbsp;";
$page_html.="<a href='index.php?page=".$next_page."'>下一页</a>&nbsp;";
$page_html.="<a href='index.php?page=$max_page'>尾页</a>";

if(empty($_GET["search"])){
 $sql='select * from t_message order by id desc limit '.$begin.','.$page_size;
}else{
  $searchText=$_GET["search"];//获取到查询关键字
  
  $sql="select * from t_message where username like '%".$searchText."%' or  message like '%".$searchText."%'";
    echo $sql;
   // select * from t_message where username like '%张三%' or message like '%张三%';
  
}
$aa=$db->query($sql);
while($row=$aa->fetch_assoc()){
    $rowlist[]=$row;
}
$aa->free_result();
$db->close();
define('ABC','abc');
require 'list_html.php';
?>





